import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;


public class FileReader {
	private Scanner scanner = null;
	private Data data = null;
	private ArrayList<Data> listOfData;
	
	public FileReader(String file){
		try {
			listOfData = new ArrayList<Data>();
			scanner = new Scanner(new File(file));
			while (scanner.hasNextLine()) {
				data = new Data();
				String line = scanner.nextLine();
				String[] attributesFromText = line.split(",\\s*");
				for (String attribute : attributesFromText){
					data.addAttribute(attribute);
				}
				listOfData.add(data);				
			}
		} catch (FileNotFoundException e) {
			System.err.println("Cannot find the file");
		} finally {
			if (scanner != null)
				scanner.close();
		}
	}
	
	public ArrayList<Data> getDataList(){
		return listOfData;
	}
}
